﻿<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<link href="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 增值管理 <span class="c-gray en">&gt;</span> 添加增值服务
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">

    <div action="" method="post" class="form form-horizontal" id="form-shops-add" enctype="multipart/form-data">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>主菜单名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="请输入4~6个字" id="primary_menu" style="width:22%;" maxlength="6">
            </div>
        </div>
        <div class="row cl" id="sub">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>子菜单名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="sub_menu1" style="width:22%;">&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="c-red">*</span>控制器/方法名：&nbsp;&nbsp;<input type="text" class="input-text" placeholder="" id="sub_control1" style="width:22%;">&nbsp;&nbsp;&nbsp;&nbsp;
                <button class="btn btn-primary radius" type="button" id="tianjia" onclick="add_sub()" >&nbsp;&nbsp;添加&nbsp;&nbsp;</button>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>费用：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="price" value="0" style="width:22%;">&nbsp;&nbsp;元
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>有效期：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="以天为单位" id="period_validity" value="1" style="width:22%;">&nbsp;&nbsp;天
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button class="btn btn-primary radius" type="submit" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <a class="btn btn-warning radius" href="{:url('index')}">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
            </div>
        </div>
    </div>

</div>
{include file="public:footer_js"}

<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">

    var count = 1;
    function add_sub(){

        count=count+1;
        var sub_menu	 = $("#sub_menu1").val();
        var sub_control	 = $("#sub_control1").val();

        if (sub_menu=="" || sub_control=="") {
            layer.msg('请填写完整的子菜单!',{icon:7,time:1000});
            return;
        }

        //清除
        $("#sub_menu1").val('');
        $("#sub_control1").val('');

        $("#sub").after("<div class=\"row cl\" id=\"sub\">\n" +
            "            <label class=\"form-label col-xs-4 col-sm-3\"><span class=\"c-red\">*</span>子菜单名称：</label>\n" +
            "            <div class=\"formControls col-xs-8 col-sm-9\">\n" +
            "                <input type=\"text\" class=\"input-text\" value='"+sub_menu+"' id=\"sub_menu"+count+"\" style=\"width:22%;\">&nbsp;&nbsp;&nbsp;&nbsp;\n" +
            "                <span class=\"c-red\">*</span>控制器/方法名：&nbsp;&nbsp;<input type=\"text\" class=\"input-text\" value='"+sub_control+"' placeholder=\"\" id=\"sub_control"+count+"\" style=\"width:22%;\">&nbsp;&nbsp;&nbsp;&nbsp;\n" +
            "            </div>\n" +
            "        </div>");
    }

    $("#submit").click(function(){

        var arr_sub  = [];
        for (var i=1;i<=count;i++){
            var sub_menu	 = $("#sub_menu"+i).val();
            var sub_control	 = $("#sub_control"+i).val();
            if (sub_menu!='' && sub_control!=''){
                var sub_item = sub_menu+"&"+sub_control;
                arr_sub.push(sub_item);
            }
        }

        var primary_menu    = $("#primary_menu").val();
        var price           = $("#price").val();
        var period_validity = $("#period_validity").val();

        // 主菜单
        if(primary_menu == ''){
            layer.msg('主菜单不可为空!',{icon:7,time:1000});
            $("#primary_menu").focus();
            return ;
        }

        if (arr_sub.length<=0){
            layer.msg('子菜单不可为空!',{icon:7,time:1000});
            $("#sub_menu1").focus();
            return ;
        }

        //异步提交数据
        $.ajax({
            type:"POST",
            url:"{:url('add')}",
            data:{
                primary_menu : primary_menu,
                arr_sub : JSON.stringify(arr_sub),
                price : price,
                period_validity : period_validity
            },
            async:true,
            success:function (res) {
                if(res.code === 0){
                    layer.msg(res.msg,{icon:5,time:2000});
                }else{
                    layer.msg(res.msg,{icon:6,time:2000});
                    setTimeout(
                        function(){
                            location.replace("{:url('index')}");
                        },
                        1000
                    );
                }
            }
        });

    });

</script>

</body>
</html>